#include <myheader_c_plus.h>
using std::cout;
using std::endl;
class Complex{
private:
    int _x;
    int _y;
public:
    Complex(int x, int y)
        :_x(x)
         ,_y(y)
    {

    }
    void print(){
        cout << _x << " " << _y << endl;
    }
    friend Complex operator+(const Complex & lhs, const Complex & rhs);

    //实现+=运算符重载，需要将函数内置为类的成员函数
    Complex & operator+=(const Complex & rhs){
        this->_x += rhs._x;
        this->_y += rhs._y;
        return *this;
    }


    //实现前置++，后置++的运算符重载
    Complex operator++(){
        ++_x;
        ++_y;
        return *this;
    }

    //实现后置++
    Complex operator++(int){
        //首先保存之前的状态
        Complex temp(*this);
        ++_x;
        ++_y;
        return temp;

    }
};
    //实现+的运算符重载,因为不改变操作数的值，所以采用友元函数进行实现。
    Complex operator+(const Complex & lhs, const Complex & rhs){
         Complex temp((lhs._x + rhs._x), (lhs._y + rhs._y));
         return temp;
    }
int main(int argc, char *argv[])
{
    Complex exp(1,3);
    Complex exp2(2,4);
    Complex exp3 = exp + exp2;
    exp3.print();
    exp += exp2;
    exp.print();
    exp++;
    exp.print();
    ++exp2;
    exp2.print();
    Complex exp4 = exp++;
    exp4.print();
    exp.print();

    return 0;
}

